/**
 * Copyright (C), 2018-2018, https://blog.fundodoo.com
 * Author:   醉探索戈壁
 * Date:     2018/7/10 下午7:33
 * Description: Athlete实体类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.fundodoo.blog.aggrid.model;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author 醉探索戈壁
 * @create 2018/7/10 下午7:33
 * @since 1.0.0
 */
@Entity
@Cacheable(false)
@Data
@ToString
@EqualsAndHashCode
public class Athlete {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Version()
    private Long version = 0L;

    private String name;

    @OneToOne()
    private Country country;

    @JsonManagedReference
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "athlete", orphanRemoval = true)
    private List<Result> results = new ArrayList<>();

    public Athlete() {
    }

    public Athlete(String name, Country country, List<Result> results) {
        this.name = name;
        this.country = country;
        this.results = results;
    }
}
